<%@ page import="com.nus.beans.Leave" %>
<%@ page import="java.util.List" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 9/22/12
  Time: 11:07 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script type="text/javascript">
        function submitForm(action) {
            form = document.getElementById('leavesForm');

            form.action = action;
            form.submit();
        }
    </script>
    <title>Leaves History</title></head>

<%
    String errorMessage = (String) request.getAttribute("ERROR_MESSAGE");

%>
<body>
<table>
    <p>Leaves History</p>
    <tr>
        <td></td>
        <td>Leave Date</td>
        <td>Applied Date</td>
        <td>Verified Date</td>
        <td>Approved Date</td>
        <td>Rejected Date</td>
        <td>Leave Status</td>
    </tr>
    <tr>
        <td colspan="6">
            <% if (errorMessage != null) { %>
            <%=errorMessage%>
            <%}%>
        </td>
    </tr>

    <form method="post" id="leavesForm">

        <% List<Leave> leaves = (List<Leave>) request.getAttribute("leavesList");
            Leave leave;
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            for (int i = 0; i < leaves.size(); i++) {
                leave = leaves.get(i);
        %>
        <% %>

        <td><input type="checkbox" name="<%= leave.getDate().getTime() %>"></td>
        <td><%= formatter.format(leave.getDate()) %>
        </td>
        <td><%= formatter.format(leave.getAppliedDate()) %>
        </td>
        <%if (leave.getVerifiedDate() != null) {%>
        <td>
            <%= formatter.format(leave.getVerifiedDate()) %>

        </td>
        </td>
        <% } else {%>
        <td></td>
        <% } %>
        <%if (leave.getApprovedDate() != null) {%>
        <td>
            <%= formatter.format(leave.getApprovedDate()) %>

        </td>

        <% } else { %>
        <td></td>
        <% } %>
        <%if (leave.getRejectedDate() != null) {%>
        <td>
            <%= formatter.format(leave.getRejectedDate()) %>

        </td>
        <% } else { %>
        <td></td>
        <% } %>
        <td><%= leave.getStatus().toString() %>
        </td>


        </tr>
        <% } %>


        <tr>
            <td colspan="2"><input type="button" value="Cancel" onclick="submitForm('cancelLeaves.do')"/></td>
            <td colspan="2"><input type="button" value="Reapply" onclick="submitForm('reapplyLeaves.do')"/></td>
            <td colspan="4"><a href="viewHome.do">Home</a></td>
        </tr>
    </form>
</table>

</body>
</html>